package org.fpp.jdk21study;

import java.util.*;

/**
 * SequencedCollections 学习
 * @author bigbird-0101
 * @date 2024-02-20 09:03
 */
public class SequencedCollectionsStudy {
    // Sequenced Collection 使用测试
    //反转的不是同一个对象 但是是 包装了的原对象 然后对原对象进行操作
    static class SequencedCollectionTest{
        public static void main(String[] args) {
            SequencedCollection<String> stringSequencedCollection=new ArrayList<>();
            stringSequencedCollection.addLast("123");
            stringSequencedCollection.addLast("12345");
            stringSequencedCollection.addLast("123456");
            //反转的不是同一个对象 但是是 包装了的原对象 然后对原对象进行操作
            SequencedCollection<String> reversed = stringSequencedCollection.reversed();
            stringSequencedCollection.removeLast();
            System.out.println(stringSequencedCollection);
        }
    }

    // Sequenced Sed 使用测试
    //反转的不是同一个对象 但是是 包装了的原对象 然后对原对象进行操作
    static class SequencedSetTest{
        public static void main(String[] args) {
            SequencedSet<String> stringSequencedSet=new LinkedHashSet<>();
            stringSequencedSet.addLast("String");
            stringSequencedSet.addLast("String1");
            SequencedSet<String> reversed = stringSequencedSet.reversed();
            String s = stringSequencedSet.removeLast();
            System.out.println(stringSequencedSet);
        }
    }

    // sequenced Map 使用测试
    // 反转的不是同一个对象 但是是 包装了的原对象 然后对原对象进行操作
    static class SequencedMapTest{
        public static void main(String[] args) {
            SequencedMap<String,String> sequencedMap=new LinkedHashMap<>();
            sequencedMap.putLast("123","1234");
            sequencedMap.putLast("1234","1234");
            sequencedMap.putLast("12345","1234");
            SequencedSet<String> stringSequencedSet = sequencedMap.sequencedKeySet();
            SequencedSet<Map.Entry<String, String>> entrySequencedSet = sequencedMap.sequencedEntrySet();
            SequencedCollection<String> stringSequencedCollection = sequencedMap.sequencedValues();
            SequencedMap<String, String> reversed = sequencedMap.reversed();
            System.out.println(reversed);
            Map.Entry<String, String> stringStringEntry = sequencedMap.pollFirstEntry();
            System.out.println(sequencedMap);
        }
    }
}
